let app = getApp()
var stylecss = require('../../utils/stylecss.js');
Component({
    properties: {
      scrollTop: {
        type: Number,
        observer: function(newVal, oldVal) {
          this.updatscroll()
        }
      },
      styleType:String,
      item: {
        type:Object
      }
      },
      data:{
      
      },
    lifetimes: {
      ready: function() {
        let that = this;
        const query = wx.createSelectorQuery().in(this)
        setTimeout(() => { 
           query.select('#'+this.data.item.id).boundingClientRect(res=>{
                that.setData({
                  top:res.top
                })
              }).exec();
         }, 0);
       },
        attached: function () {
          var list=this.data.item.list;
          var css=stylecss.css(this.data.item.id);
          var anima=stylecss.animated(this.data.item.id);
          this.setData({
            oldanima:anima,
            anima:anima,
            css:css
          })
          var id2=this.data.item.id+' .item_image';
          var a_title=this.data.item.id+' .a_title';
          var a_desc=this.data.item.id+' .a_desc';
          var a_time=this.data.item.id+' .a_time';

          var group_item=this.data.item.id+' .group_item';
          var item_image=this.data.item.id+' .item_image';
          var group_title=this.data.item.id+' .group_title';
          var group_desc=this.data.item.id+' .group_desc';

          var group_item_css=stylecss.css(group_item);
          var item_image_css=stylecss.css(item_image);
          var group_title_css=stylecss.css(group_title);
          var group_desc_css=stylecss.css(group_desc);

          var css2=stylecss.css(id2);
          var a_title_css=stylecss.css(a_title);
          var a_desc_css=stylecss.css(a_desc);
          var a_time_css=stylecss.css(a_time);
          this.setData({
            list:list,
            css:css,
            css2:css2,
            a_title_css:a_title_css,
            a_desc_css:a_desc_css,
            a_time_css:a_time_css,
            group_item_css:group_item_css,
            item_image_css:item_image_css,
            group_title_css:group_title_css,
            group_desc_css:group_desc_css,
          })
       }
      },
    methods: {
      updatscroll:function(){
        var nowtop=this.data.scrollTop-this.data.top
        var oldanima=this.data.oldanima
        if(nowtop<=0){
         this.setData({
           anima:oldanima
         })
        }else{
          this.setData({
              anima:''
          })
        }
     },
      jumpdetail:function(e){
          var id=e.currentTarget.dataset.id
          wx.navigateTo({ 
            url: '/yb_shopv2/native/all/index?type=article&id='+id,
         }) 
      }
    }
});
